package kassiopeia.commons.util;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import org.custommonkey.xmlunit.XMLTestCase;
import org.w3c.tidy.Tidy;
import org.xml.sax.SAXException;

public class AssertUtils {

    public static void assertXMLEqual(String expected, String actual) throws SAXException, IOException {
        new XMLTestCase(){}.assertXMLEqual(tidy(expected), tidy(actual));
    }

    private static String tidy(String inputXml) {
        Tidy tidy = new Tidy();
        tidy.setXmlTags(true);
        tidy.setXmlOut(true);

        ByteArrayInputStream bin = new ByteArrayInputStream(inputXml.getBytes());
        ByteArrayOutputStream bout = new ByteArrayOutputStream();

        tidy.parse(bin, bout);

        return bout.toString();
    }

}
